var express = require('express');
var router = express.Router();
var  mockjs=require('mockjs')



router.post('upload', (req,res,next)=>{
  let data=mockjs.mock({
      "url":"@image"
  })
})
/* GET home page. */

router.get('/qa/toplist', function(req, res, next) {
  let data=mockjs.mock({
    "data": [{
      "id": "1",
      "labelname": "JAVA"
    },
      {
        "id": "2",
        "labelname": "PHP"
      },
      {
        "id": "3",
        "labelname": "前端"
      },
      {
        "id": "4",
        "labelname": "Python"
      }
    ]


  })
  res.send(data)
});
router.get('/qa/list/:id/:type/:page/:size', function(req, res, next) {
  let data=mockjs.mock({
    "data": {
      "total": "@integer(60, 100)",
      "rows|10": [{
        "id": "@integer(1, 1000)",
        "title": "@cword(20,30)",
        "content": "@string",
        "createtime": "@date",
        "updatetime": "@datetime",
        "userid": "@integer(1, 1000)",
        "nickname": "@cname",
        "visits": "@integer(60, 100)",
        "thumbup": "@integer(60, 100)",
        "lookmath": "@integer(60, 100)",
        "reply": "@integer(60, 100)",
        "solve": "@string",
        "replyname": "小牛",
        "replytime": "@datetime"
      }]
    }



  })
  res.send(data)
});


router.get('/gathering/search/:page/:size', function(req, res, next) {
/*  console.log(req.params.page);
  console.log(req.params.size);*/
  let data=mockjs.mock({
    "flag": true,
    "code": 20000,
    "message": "@string",
    "data": {
      "total": "@integer(60, 100)",
      "rows|12": [{
        "id": "@string",
        "name": "@cword(8,12)",
        "summary": "@cword(20,40)",
        "detail": "@cword(20,40)",
        "sponsor": "@string",
        "image": "https://img-bss.csdnimg.cn/201908070843267832.jpg",
        "starttime": "@date",
        "endtime": "@date",
        "address": "@county(true)",
        "enrolltime": "@date",
        "state": "1",
        "city": "@city"
      }]
    }
  })
  res.send(data)
});
router.get('/gathering/detail/:id', function(req, res, next) {
/*  console.log(req.params.page);
  console.log(req.params.size);*/
  let data=mockjs.mock({
      "item": {
        "id": "@string",
        "name": "@cword(8,12)",
        "summary": "@cword(100,140)",
        "detail":  "@cword(200,240)",
        "sponsor": "@string",
        "image": "https://img-bss.csdnimg.cn/201908070843267832.jpg",
        "starttime": "@date",
        "endtime": "@date",
        "address": "@county(true)",
        "enrolltime": "@date",
        "state": "1",
        "city": "@city"
      }
  })
  res.send(data)
});

router.get('/spit/search/:page/:size', function(req, res, next) {
  /*  console.log(req.params.page);
    console.log(req.params.size);*/
  let data=mockjs.mock({
    "flag": true,
    "code": 20000,
    "message": "@string",
    "data": {
      "total": "@integer(60, 100)",
      "rows|10": [{
        "id": "@string",
        "content": "@cword(100,200)",
        "publishtime": "@datetime",
        "userid": "@string",
        "nickname": "小cc",
        "visits": "@integer(60, 100)",
        "thumbup": "@integer(60, 100)",
        "share": "@integer(60, 100)",
        "comment": "@integer(60, 100)",
        "state": "@string",
        "parentid": "@string"
      }]

    }
  })
  res.send(data)
});
router.get('/spit/detail/:id', function(req, res, next) {
  /*  console.log(req.params.page);
    console.log(req.params.size);*/
  let data=mockjs.mock({
    "data": {
      "id": "@string",
      "nikename": "@cname",
      "content": "@cword(100,300)",
      "publishtime": "@datetime",
      "thumbup": "@integer(60, 100)",
      "share": "@integer(60, 100)",
      "comment": "@integer(60, 100)"
    }
  })
  res.send(data)
});
router.put('/spit/thumbup/:id', function(req, res, next) {
  /*  console.log(req.params.page);
    console.log(req.params.size);*/
  let data=mockjs.mock({
    "data": {
      "code": 20000,
      "flag": true,
      "message": "执行成功"
    }
  })
  res.send(data)
});
router.post('/spit/submit', function(req, res, next) {
  /*  console.log(req.params.page);
    console.log(req.params.size);*/
  let data=mockjs.mock({
    "data": {
      "code": 20000,
      "flag": true,
      "message": "发布成功"
    }
  })
  res.send(data)
});
router.post('/spit/save', function(req, res, next) {
  console.log(req.body);
  let data=mockjs.mock({
    "data": {
      "code": 20000,
      "flag": true,
      "message": "回复成功"
    }
  })
  res.send(data)
});
router.get('/spit/commentlist/:id', function(req, res, next) {
  /*  console.log(req.params.page);
    console.log(req.params.size);*/
  let data=mockjs.mock({
        "code": 20000,
        "flag": true,
        "message": "@string",
        "data|10": [{
          "id": "@string",
          "content": "@cword(25,35)",
          "nikename": "@cname",
          "publishtime": "@datetime",
          "thumbup": "@integer(60, 100)"
        }]
      }
  )
  res.send(data)
});


router.get('/recruit/recommendlist', function(req, res, next) {
  let data=mockjs.mock({
      "data|4": [
        {
          "id": "@string",
          "name": "@cword(4,5)",
          "sponsor": "@string",
          "time|4-9":0,
          "salarylow|4-8":0,
          "salarymore|10-20":0,
          "address": "@county(true)",
          "enrolltime": "@date",
          "city": "@city",
          "require1":"@string",
          "require2":"@string",
        }
      ]

  })
  res.send(data)
});
router.get('/recruit/newlist', function(req, res, next) {
  let data=mockjs.mock({
      "data|12": [
        {
          "id": "@string",
          "name": "@cword(4,5)",
          "sponsor": "@string",
          "time|4-9":0,
          "salarylow|4-8":0,
          "salarymore|10-20":0,
          "address": "@county(true)",
          "enrolltime": "@date",
          "city": "@city",
          "require1":"@string",
          "require2":"@string",
        }
      ]

  })
  res.send(data)
});
router.get('/recruit/detail/:id', function(req, res, next) {
  let data=mockjs.mock({
    "data": {
      "id": "@string",
      "name": "@cword(4,6)",
      "content1": "@cword(120,180)",
      "content2":  "@cword(200,240)",
      "salarylow|4-8":0,
      "salarymore|10-20":0,
      "starttime": "@date",
      "time|4-9":0,
      "require1":"@string",
      "require2":"@string",
    }
  })
  res.send(data)
});
router.post('/user/code',(req,res,next)=>{
  let {username} =req.body
  let data=mockjs.mock({
    "code": 20000,
    "flag": true,
    "message": "验证码发送成功",
    "data":{
      "codemsg":Math.random().toString().slice(2, 6).toLowerCase()
    }
  })
  res.send(data)
  clearTimeout(this.time)
})
router.post('/user/login',(req,res,next)=>{
  let ccdata=mockjs.mock({
    "code": 20000,
    "flag": true,
    "data": {
      "token": "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiLOHflaONj9IfWIVj8gSbbMOiI5ODcyNTUxMDQ1NDM1MjY5MTIiLCJpYXQiOjE1MjQyMTQ5NDgsInJvbGVzIjoidXNlciIsImV4cCI6MTUyNDIxNTMwOH0icFRMKfaHlPn224hU3Gm",
      "name": "小小新",
      "avatar": 'http://img.duoziwang.com/2016/12/14/0824163884.jpg'

    }

  })
  let admindata=mockjs.mock({
    "code": 20000,
    "flag": true,
    "data": {
      "token": "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiLOHflaONj9IfWIVj8gSbbMOiI5ODcyNTUxMDQ1NDM1MjY5MTIiLCJpYXQiOjE1MjQyMTQ5NDgsInJvbGVzIjoidXNlciIsImV4cCI6MTUyNDIxNTMwOH0icFRMKfaHlPn224hU3Gm",
      "name": "小白",
      "avatar": 'https://b-ssl.duitang.com/uploads/item/201804/22/20180422144140_uplbi.thumb.224_0.jpg'

    }

  })
  let{username,password} =req.body
    if (username=='cc'&&password=='cc'){
      res.send(ccdata)
    } else if (username=='admin'&&password=='123') {
      res.send(admindata)
    }else {
      res.send({
        'code':402
      })
    }

  clearTimeout(this.time)
})


module.exports = router;
